package com.nb.mapper;

import com.mybatisflex.core.BaseMapper;
import com.nb.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 根据用户ID查询角色列表
     * @param userId 用户ID
     * @return 角色列表
     */
    @Select("select r.code from sys_role_user ru left join sys_role r on ru.role_id=r.id where ru.user_id=#{userId}")
    List<String> selectRoleCodeListByUserId(Long userId);

    @Select("select r.id from sys_role_user ru left join sys_role r on ru.role_id=r.id where ru.user_id=#{userId}")
    List<Long> selectRoleIdListByUserId(Long userId);

    @Select("select r.name from sys_role_user ru left join sys_role r on ru.role_id=r.id where ru.user_id=#{userId}")
    List<String> selectRoleNameListByUserId(Long userId);



    /**
     * 根据角色列表查询权限列表
     * @param roleCodeList 角色列表
     * @return 权限列表
     */
    List<Long> selectAclIdListByRoleCodeList(@Param("roleCodeList") List<String> roleCodeList);

    /**
     * 根据角色ID查询权限ID列表
     */
    @Select("select acl_id from sys_role_acl where role_id=#{roleId}")
    List<Long> selectAclIdListByRoleId(Long roleId);
    /**
     * 根据角色ID查询用户ID列表
     */
    @Select("select user_id from sys_role_user where role_id=#{roleId}")
    List<Long> selectUserIdListByRoleId(Long roleId);
}
